package com.amit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
	
	String state=null;
	String email=null;
	String phone=null;
	String city=null;
	@Override
	public void init(ServletConfig config) throws ServletException {
		
		System.out.println("init()");
		//1.collect the config parameters
		
		 email=config.getInitParameter("email");
		 phone=config.getInitParameter("phone");
		
		//2.collect the context parameter
		
		ServletContext context=config.getServletContext();
		
		 city=context.getInitParameter("city");
		 state=context.getInitParameter("state");
		
	
	}
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("service()");
		//3.collect the request parameters
		
		String fn=request.getParameter("fname");
		String ln=request.getParameter("lname");
		
		//4.proces the data
		
		System.out.println("First name:"+fn);
		System.out.println("Last name:"+ln);
		System.out.println("email:"+email);
		System.out.println("phone:"+phone);
		System.out.println("city:"+city);
		System.out.println("state:"+state);
		
		//4.send the response
		
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		
		out.println("<h1>Java Learning Center</h1>");
		out.println("<h1>ok done</h1>");
		
	
		
	}
	
	@Override
	public void destroy() {
	
		System.out.println("destroy");
		
	}

}
